package com.sebiotec.manager.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;

import com.allen.library.base.BaseHttpUtil;
import com.allen.library.interceptor.Transformer;
import com.allen.library.observer.CommonObserver;
import com.sebiotec.basecommon.utils.constant.SjmConstant;
import com.sebiotec.basecommon.utils.language.LocalManageUtil;
import com.sebiotec.basecommon.utils.tools.ActivityTool;
import com.sebiotec.basecommon.utils.tools.SPUtils;
import com.sebiotec.manager.model.SearchEntrty;
import com.sebiotec.manager.model.post.PostHistoryBean;
import com.sebiotec.manager.net.BookApiHelper;


import java.util.HashMap;

public class HistoryViewModel extends AndroidViewModel {
    public HistoryViewModel(@NonNull Application application) {
        super(application);
    }

    public MyHistoryDataCallBack mDataCallBack;

    //数据回调接口
    public interface MyHistoryDataCallBack<T> {
        void onDataSuccessCallBack(T t);
        void onDataFailCallBack(T t);
    }



    //获取UpComing数据
    public void   getHistoryData(String date, String Filter, int PageIndex, int PageSize, MyHistoryDataCallBack<Object> mDataCallBack){


        HashMap<String,Object> map=new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(SjmConstant.LOGINID,""));
        map.put("Token", SPUtils.get(SjmConstant.TOKEN,""));
        map.put("Lang", LocalManageUtil.getSMJSetLanguageLocales(ActivityTool.getInstance().getLastActivity()));
        PostHistoryBean bean =new PostHistoryBean(date,Filter,PageIndex,PageSize);

        BookApiHelper.geRadomApi()
                .getHistoryBookings(map,new BaseHttpUtil<PostHistoryBean>().convertVo2Json(bean))
                .compose(Transformer.<SearchEntrty>switchSchedulers())
                .subscribe(new CommonObserver<SearchEntrty>() {
                    @Override
                    protected String setTag() {
                        return "ManagerHist";
                    }

                    @Override
                    protected void onError(String errorMsg) {
                        mDataCallBack.onDataFailCallBack(errorMsg);
                    }

                    @Override
                    protected void onSuccess(SearchEntrty s) {
//                        SearchEntrty dashboardResponse = GsonUtil.getGson().fromJson(s, SearchEntrty.class);
                        //回调数据
                        mDataCallBack.onDataSuccessCallBack(s);
                    }
                });


    }






}
